import { h, render } from "vue";
import SealConfirm from "./confirm.vue";

//  <Confirm text="确定要删除吗?" title="我是标题"></Confirm>
type ParamsType = {
  title?: string;
  text: string;
};

const div = document.createElement("div");
div.setAttribute("class", "seal-confirm-container");
document.body.appendChild(div);

export default function Confirm({ title, text }: ParamsType) {
  return new Promise((resolve, reject) => {
    const confirmCallback = () => {
      render(null, div);
      resolve(undefined);
    };
    const cancelCallback = () => {
      render(null, div);
      reject();
    };

    const vNode = h(SealConfirm, {
      title: title,
      text: text,
      confirmCallback: confirmCallback,
      cancelCallback: cancelCallback,
    });
    render(vNode, div);
  });
}

// 关闭弹出框 render(null,div)
